<?php

namespace admin\assets;

use yii\web\AssetBundle;

/**
 * Main frontend application asset bundle.
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';

    public function registerAssetFiles($view)
    {
        //改写新增版本号
        $version = defined("VERSION") ? VERSION : time();
        $this->css = [
            '/static/js/layui/css/layui.css',
            '/static/css/admin.css',
        ];

        $this->js = [
            '/static/js/jquery-1.11.1.min.js',
            '/static/js/layer/layer.js',
            '/static/js/layui/layui.js',
            '/static/js/admin.js',
            //'/static/js/md5.js',
        ];

        parent::registerAssetFiles($view);
    }

    //依赖的资源包
    public $depends = [
        // 不需要,注释掉
//         'yii\web\YiiAsset',
//         'yii\bootstrap\BootstrapAsset',
    ];

    //定义按需加载css方法，加载js是同样的方法,并加上版本号控制
    public static function addCss($view, $cssfile) {
        $view->registerCssFile($cssfile.'?ver='.VERSION, [AppAsset::className(), 'depends' => 'admin\assets\AppAsset']);

    }

    //导入当前页的功能js文件，注意加载顺序，这个应该最后调用
    public static function addJs($view, $jsfile) {
        $view->registerJsFile($jsfile.'?ver='.VERSION, [AppAsset::className(), 'depends' => 'admin\assets\AppAsset']);
    }

}
